import React, { Component } from "react"

import List from "./list"
import Add from "./add"
export default class Home extends Component{
    constructor(props){
        super(props)
        this.state={
            arr:[
                {info:"xox122",status:1},
                {info:"xox23",status:1},
                {info:"xox3",status:1},
                {info:"xox4",status:1},
                {info:"xox5",status:1},
            ]
        }
    }
    chuangval(){
        return this.state.arr.map((item,index)=>{
            return (<List info={item.info} key={index} index={index} del={this.delindex}></List>)
        })
    }
    delindex=(val)=>{
        // console.log(val);
        let newarr = this.state.arr;
        newarr.splice(val,1)
        this.setState({
            arr:newarr
        })
    }
    add=(val)=>{
        let newarr = this.state.arr;
        newarr.push({info:val,status:1});
        this.setState({
            arr:newarr
        })
        console.log(newarr)
    }
    render(){
        return(
            <div>
                <Add addval={this.add}></Add>
                <ul >
                    {this.chuangval()}
                </ul>
            </div>
        )
    }
}
